package com.xinchen.all.app

import androidx.lifecycle.ViewModelStore
import com.huyuhui.fastble.BleManager
import com.huyuhui.fastble.common.BleConnectStrategy
import com.maple.base.app.BaseApp
import com.maple.utils.const.UtilsInit
import com.zhzc0x.bluetooth.BluetoothClient

class MyApplication: BaseApp() {

    companion object {
        @JvmStatic
        lateinit var instance: MyApplication
            private set
    }

    override fun getAppPackageName(): String = this.packageName

    override fun initApp() {
        super.initApp()
        instance = this
        UtilsInit.init(getAppPackageName())
        initBle()
    }

    override val viewModelStore: ViewModelStore
        get() = ViewModelStore()


    private fun initBle() {
//        BleManager.get().init(this,
//            BleOptions.Builder()
//                .setScanMillisTimeOut(5000)
//                .setConnectMillisTimeOut(5000)
        //一般不推荐autoSetMtu，因为如果设置的等待时间会影响其他操作
//                .setMtu(100, true)
//                .setMaxConnectNum(2)
//                .setConnectRetryCountAndInterval(2, 1000)
//                .build()
//        )
//        BleManager.get().registerBluetoothStateReceiver {
//            onStateOff {
//
//            }
//        }

//               val option = BleOptions.Builder()
//                .setScanMillisTimeOut(5000)
//                .setConnectMillisTimeOut(5000)
//                .build()
//        BleManager.get().init(this,option)


        BleManager.apply {
            enableLog(true)
            maxConnectCount = 5
            operateTimeout = 2000
            splitWriteNum = 20
            bleConnectStrategy = BleConnectStrategy.Builder().setConnectOverTime(10000)
                .setConnectBackpressureStrategy(BleConnectStrategy.CONNECT_BACKPRESSURE_DROP)
                .setReConnectCount(1).setReConnectInterval(2000).build()
        }.init(this)
    }
}